<?php
class user extends Activity {
    protected $userMode;

    function __construct() {
        $this->userMode=UserModule::init();
    }
    function indexTask(){
        $result=array();
        View::displayAsHtml($result,"login.php");
    }

    function loginSubmitTask($user, $pass){
        $loginRe=$this->userMode->login($user,$pass);
        if($loginRe->judgeState()){
            $url=WebRouter::init()->getPage('dash',"index");
            View::displayAsTips($url);
        }else{
            View::displayDataMessage($loginRe);
        }
    }

    function registerSubmitTask($data=array()){
        $user = UserModule::init('likyh_user','likyh_user_info');
        $data['type'] = "user";
        View::displayDataMessage($user->register($data));
    }

    function getLoginInfoTask(){
        $this->user=UserModule::init();
        $result['ifLogin']=!is_null($this->userMode->getLoginId());
        if($result['ifLogin']){
            $result['user_id']=$this->userMode->getLoginId();
            $result['user_info']=$this->userMode->getLoginInfo();
        }
        View::displayAsJson($result);
    }
}